(function () {
    nsbase.utility.validations = new ValidationsFunc();

    function ValidationsFunc() {
        var _self = this;

        function _init() {
            _self.urlValidate = UrlValidate;
            _self.videoValidate = VideoValidate;
            _self.ipValidate = IpValidate;
            _self.emailValidate = EmailValidate;
            _self.telephoneValidate = TelephoneValidate;
            _self.phoneValidate = PhoneValidate;
            _self.intValidate = IntValidate;
            _self.floatValidate = FloatValidate;
            _self.isNullOrEmpty = isNullOrEmpty;
            _self.isNullOrWhiteSpace = isNullOrWhiteSpace;
        }
        
        function isNullOrEmpty (str){
            return str == null|| str == "";
        }
        
        function isNullOrWhiteSpace (str){
            if(!str)
                return true;
            return isNullOrEmpty(nsbase.utility.trim(str));
        }
    
        function UrlValidate(url) {
            // method 1
            // var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
            // + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"
            // //ftp的user@
            // + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
            // + "|" // 允许IP和DOMAIN（域名）
            // + "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
            // + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
            // + "[a-z]{2,6})" // first level domain- .com or .museum
            // + "(:[0-9]{1,4})?" // 端口- :80
            // + "((/?)|" // a slash isn't required if there is no file name
            // + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";

            // var strRegex = "^((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)?((([a-zA-Z0-9_-]\.?)+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&amp;%+_\./-~-]*)?$";
            // var re = new RegExp(strRegex, "i");

            // method 2
            var urlRegex = /^https?:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
            return urlRegex.test(url);
        };

        function VideoValidate(url) {
            var urlRegex = /^https?:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*.swf$/;
            return urlRegex.test(url);
        };
        function IpValidate(ip) {
            var ipRegex = /^(\d{1,3}\.){3}\d{1,3}([\?\/]?)*/
            return ipRegex.test(ip);
        }

        function EmailValidate(email) {
            var emailRegex = /^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/;
            return emailRegex.test(email);
        }

        function TelephoneValidate(telephone) {
            var telephoneRegex = /^[1][3-8]\d{9}$/;
            return telephoneRegex.test(telephone);
        }
        
        function PhoneValidate(phone){
            var phoneRegex = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
            return phoneRegex.test(phone);
        }
        
        function IntValidate(int) {
            var intRegex = /^\d+$/;
            return intRegex.test(int);
        }

        function FloatValidate(float,num) {
            var strRegex = "^\\d+[.]?[\\d]{0,"+ num +"}$";
            var re = new RegExp(strRegex, "g");
            return re.test(float);
        }
        _init();
    };
})();